# _*_ coding: utf-8 _*_
from odoo import models, fields, api


class StockMove(models.Model):
    _inherit = "stock.move"

    duplicated_info = fields.Text("内部参考重复", compute="_compute_duplicated_info")

    @api.depends("active_move_lot_ids.board_number")
    def _compute_duplicated_info(self):
        def make_info(move, lot):
            domain =[
                ('board_number', '=', lot.board_number),
            ]
            if isinstance(lot.id,int):
                domain.append(("id", "!=", lot.id))
            is_duplicated = self.env["stock.move.lots"].search_count(domain) > 0
            if not is_duplicated:
                if move.active_move_lot_ids and any(lot.board_number == move_lot.board_number
                                                    for move_lot in move.active_move_lot_ids-lot):
                    is_duplicated = True
            if is_duplicated:
                return "内部参考：%s 重复了。" % lot.board_number
            else:
                return ""
        for move in self:
            res = (make_info(move, lot) for lot in move.active_move_lot_ids if lot.board_number)
            move.duplicated_info = "\n".join(r for r in res if r)
